package com.example.wnn.activiti;

import org.activiti.bpmn.model.EndEvent;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.bpmn.model.UserTask;

import java.util.Arrays;
import java.util.UUID;

public class WorkflowUtils {

    public  static final String TASKID ="sid%s-%s";


    //创建task
    public static  UserTask createUserTask(String id, String name, String candidateGroups) {
        UserTask userTask = new UserTask();
        userTask.setName(name);
        userTask.setId(id);
        userTask.setCandidateGroups(Arrays.asList(candidateGroups));
        return userTask;
    }


    //创建箭头
    public static  SequenceFlow createSequenceFlow(String from, String to) {
        SequenceFlow flow = new SequenceFlow();
        flow.setSourceRef(from);
        flow.setTargetRef(to);
        return flow;
    }


    public static  StartEvent createStartEvent() {
        StartEvent startEvent = new StartEvent();
        startEvent.setId(String.format(TASKID,"START",getUUID()));
        return startEvent;
    }


    public static  EndEvent createEndEvent() {
        EndEvent endEvent = new EndEvent();
        endEvent.setId(String.format(TASKID,"END",getUUID()));
        return endEvent;
    }

    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-","");
    }

}
